﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Zj.HttpCodeDemo.ConsoleView.Sample
{
    public class FunctionalProgrammingSample
    {
        public static void Sample()
        {
            var person = new Person("张","建");
            Console.WriteLine("***********************************************");
            Console.WriteLine("                              LastName:");
            Console.WriteLine($"                                      {person.LastName}");
            person = person.With(person,"张","骞");
            person = person.With("张", "文");
            Console.WriteLine("                              LastName:");
            Console.WriteLine($"                                      {person.LastName}");
            Console.WriteLine();
        }
    }
    public class Person
    {
        public Person(string firstName, string lastName)
        {
            this.FirstName = firstName;
            this.LastName = lastName;
        }
        public string FirstName { get; set; }
        public string LastName { get; set; }


        public Person With(Person person, string firstName, string lastName)
        {
            return new Person(firstName ?? person.FirstName
                , lastName ?? person.LastName);
        }

        public Person With(string firstName, string lastName)
        {
            this.FirstName = firstName ?? this.FirstName;
            this.LastName = lastName ?? this.LastName;
            return this;
        }
    }
}
